package com.hycat.mail.cart.controller;

import com.hycat.mail.cart.service.CartService;
import com.hycat.mail.cart.vo.Cart;
import com.hycat.mail.cart.vo.CartItem;
import com.hycat.mail.common.interceptor.AuthInterceptor;
import com.hycat.mail.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 吕泽浩业
 * @version 1.0
 */
@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private CartService cartService;

    @PostMapping("/addCart")
    public R addCart(@RequestParam("skuId") Long skuId,
                     @RequestParam("count") Integer count) {
        CartItem cartItem = cartService.addCart(skuId, count, AuthInterceptor.threadLocal.get());
        return R.ok("添加购物车成功").put("data", cartItem);
    }

    @GetMapping("/listCart/{memberId}")
    public R listCart(@PathVariable("memberId") Long memberId) {
        Cart cart = cartService.listCart(memberId);
        return R.ok("购物车列表如下").put("data", cart);
    }

    @GetMapping("listOrderCart")
    public Cart listOrderCart(@PathVariable("memberId") Long memberId) {
        return cartService.listOrderCart(memberId);
    }

}
